<?php

/**
 * This is the model class for table "dbm_history".
 *
 * The followings are the available columns in table 'dbm_history':
 * @property integer $id ID
 * @property string $table_name Table Name
 * @property string $sql Sql
 * @property string $diff_last Diff Last
 * @property string $create_time Create Time
 * @property string $remark Remark
 * @property string $author Author
 * @property string $title Title
 * @property string $package 包
 */
class DbmHistory extends DbmActiveRecord
{
	
	public function lastUpdate($tableName) {
		$criteria = new CDbCriteria();
		$criteria->order = 'create_time DESC';
		$criteria->addColumnCondition(array(
			'table_name' => $tableName,
		));
		return $this->find($criteria);
	}
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return DbmHistory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function getMdcClass() {
		return 'dbMonitor.models.metadata.DbmHistoryMetadata';
	}
	
	/**
	 * behavior 如果要继承使用父类的 behaviors 请使用 array_merge 方法
	 * 否则直接返回 array 数组
	 */
	public function behaviors() {
		return array_merge(parent::behaviors(), array(
			'autoCreatetime' => array(
				'class' => 'lib.behaviors.auto.CCreateTime',
				'attribute' => 'create_time'
			),
		));
	}
	
	/**
	 * @return array relational rules.
	 */
	public function relations() {
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array_merge(parent::relations(), array(
		));
	}
	
	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array_merge(parent::rules(), array(
		));
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array_merge(parent::attributeLabels(), array(
		));
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('table_name',$this->table_name,true);
		$criteria->compare('sql',$this->sql,true);
		$criteria->compare('diff_last',$this->diff_last,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('author',$this->author,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('package',$this->package,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}